/* -*- C -*- */
/*
 * Copyright (c) 2007 Massachusetts Institute of Technology
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

#include <stdlib.h>
#include <spu_intrinsics.h>
#include <spu_mfcio.h>
#include "fftw-spu.h"
#include "../fftw-cell.h"

static void wait(void)
{
     (void) spu_read_in_mbox();
}

int main(unsigned long long spu_id, unsigned long long parm)
{  
     static struct spu_context ctx __attribute__ ((aligned (ALIGNMENT)));
     UNUSED(spu_id);
     spu_writech(MFC_WrTagMask, -1);

     for (;;) {
	  wait();

	  /* obtain context */
	  X(spu_dma1d)(&ctx, parm, sizeof(ctx), MFC_GET_CMD);

	  switch (ctx.op) {
	      case FFTW_SPE_DFT:
		   X(spu_do_dft)(&ctx.u.dft);
		   break;

	      case FFTW_SPE_TRANSPOSE:
		   X(spu_do_transpose)(&ctx.u.transpose);
		   break;

	      case FFTW_SPE_COPY:
		   X(spu_do_copy)(&ctx.u.copy);
		   break;

	      case FFTW_SPE_EXIT:
		   return 0;
	  }

	  /* signal completion: */
	  ctx.done = 1;
	  X(spu_dma1d)(&ctx, parm, sizeof(ctx), MFC_PUTF_CMD);
     }
}
